using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MediaPortal.GUI.Rss
{
    public partial class uTorrentSetupForm : Form
    {
        public uTorrentSetupForm()
        {
            InitializeComponent();

            this.LoadSettings();
        }

        private void LoadSettings()
        {
            MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings("MediaPortal.xml");

            string lUrl = xmlreader.GetValue("torrents", "uTorrent.url");
            string lLogin = xmlreader.GetValue("torrents", "uTorrent.Login");
            string lPassword = xmlreader.GetValue("torrents", "uTorrent.Password");
            string lSeconds = xmlreader.GetValue("torrents", "uTorrent.seconds");

            if (lUrl.Length > 0) this.tbxURL.Text = lUrl;
            if (lSeconds.Length > 0) this.tbxSeconds.Text = lSeconds;

            this.tbxLogin.Text = lLogin;
            this.tbxPassword.Text = lPassword;
        }

        private void SaveSettings()
        {
            MediaPortal.Profile.Settings xmlwriter = new MediaPortal.Profile.Settings("MediaPortal.xml");
            xmlwriter.SetValue("torrents", "uTorrent.url", this.tbxURL.Text);
            xmlwriter.SetValue("torrents", "uTorrent.Login", this.tbxLogin.Text);
            xmlwriter.SetValue("torrents", "uTorrent.Password", this.tbxPassword.Text);
            xmlwriter.SetValue("torrents", "uTorrent.seconds", this.tbxSeconds.Text);
        }

        private void bttnOK_Click(object sender, EventArgs e)
        {
            this.SaveSettings();
            this.Close();
        }

        private void bttnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}